package com.stylefeng.guns.modular.vpn.core.log;

import com.stylefeng.guns.core.db.Db;
import com.stylefeng.guns.modular.system.dao.VpnOperationLogMapper;
import com.stylefeng.guns.modular.vpn.entity.VpnOperationLog;
import com.stylefeng.guns.modular.vpn_operation_log.service.impl.VpnOperationLogServiceImpl;
import lombok.extern.slf4j.Slf4j;

import java.util.TimerTask;

/**
 * @Description VPN日志记录
 * @Author Mr.GodRui
 * @Date 2020-04-20 17:01
 **/
@Slf4j
public class VpnLogTaskFactory {
    private static VpnOperationLogServiceImpl vpnOperationLogService = Db.getMapper(VpnOperationLogServiceImpl.class);



    public static TimerTask operationLog(final Integer roleId,
                                         final String roleName,
                                         final String itemName,
                                         final String content) {
        return new TimerTask() {
            @Override
            public void run() {
                try {
                    VpnOperationLog vpnOperationLog = new VpnOperationLog();
                    vpnOperationLog.setRoleId(roleId);
                    vpnOperationLog.setItemName(itemName);
                    vpnOperationLog.setRoleName(roleName);
                    vpnOperationLog.setContent(content);
                    vpnOperationLogService.saveOneOperationLog(vpnOperationLog);
                } catch (Exception e) {
                    log.error("创建操作日志异常!", e);
                }
            }
        };
    }

}
